package org.batyrov.equery.bean;

import org.batyrov.equery.bean.Service;
import org.batyrov.equery.bean.User;
import org.batyrov.equery.bean.Window;
import org.batyrov.equery.dao.Dao;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Date;
import java.math.BigInteger;

/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 08.09.2009
 * Time: 0:19:57
 * To change this template use File | Settings | File Templates.
 */
@Table(name = "t_equery")
@Entity
public class Client {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column
    private int number;

    @Column(name="take_date")
    private Date takeDate;

    @Column(name="call_date")
    private Date callDate;

    @Column(name="finish_date")
    private Date finishDate;

    @Column
    private int status;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public Date getTakeDate() {
        return takeDate;
    }

    public void setTakeDate(Date takeDate) {
        this.takeDate = takeDate;
    }

    public Date getCallDate() {
        return callDate;
    }

    public void setCallDate(Date callDate) {
        this.callDate = callDate;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @ManyToOne
    @JoinColumn(name = "service_id")
    private Service service;

    public Service getService() {
        return service;
    }

    public void setService(Service service) {
        this.service = service;
    }

    @ManyToOne
    @JoinColumn(name="user_id")
    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne
    @JoinColumn(name = "window_id")
    private Window window;

    public Window getWindow() {
        return window;
    }

    public void setWindow(Window window) {
        this.window = window;
    }

    @PrePersist
    void prePersist() {
        Query q = Dao.getEntityManager().createNativeQuery("select nextval('t_equery_number_seq')");
        number = ((BigInteger)q.getSingleResult()).intValue();
    }
}
